package com.example.github.reflect.demo;

import com.example.github.reflect.entity.Person;

import java.lang.reflect.Constructor;

public class ReflectConstructor {
    public static void main(String[] args) throws Exception {
        Class<Person> personClass = Person.class;
        // 获取全参构造方法
        Constructor<Person> allConstructor = personClass.getConstructor(String.class, int.class);
        // 设置值
        Person person = allConstructor.newInstance("张三", 15);
        System.out.println(person);

        System.out.println("===================");
        // 获取空参构造方法
        Constructor<Person> constructor = personClass.getConstructor();
        Person person1 = constructor.newInstance();
        System.out.println(person1);
    }
}
